package com.apache.passport.entity;

import com.apache.api.entity.BaseEntity;
import com.apache.tools.StrUtil;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * description:  用户表
 *
 * @author Hou Dayu 创建时间：2016-12-18
 */
@SuppressWarnings("serial")
public class UctUser extends BaseEntity {

    private String userId;

    private String userEname;

    private String userCname;

    private String userPass;

    private Integer userStatus;

    private String email;

    private String mobile;

    private String regIp;

    private Long createTime;

    //2015年1月28日16:01:47  添加 添加用户删除标示 如果无此值,则uc无法查看当前用户
    private String delStatus;

    //private String regSource;
    private String userType;

    private String customerType;

    private Integer userLevel;

    private String orgEname;

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("userId=" + this.userId + ";");
        sb.append("userEname=" + this.userEname + ";");
        sb.append("userCname=" + this.userCname + ";");
        sb.append("userPass=" + this.userPass + ";");
        sb.append("userStatus=" + this.userStatus + ";");
        sb.append("email=" + this.email + ";");
        sb.append("mobile=" + this.mobile + ";");
        sb.append("regIp=" + this.regIp + ";");
        sb.append("createTime=" + this.createTime + ";");
        sb.append("delStatus=" + this.delStatus + ";");
        sb.append("userType=" + this.userType + ";");
        sb.append("customerType=" + this.customerType + ";");
        sb.append("userLevel=" + this.userLevel + ";");
        return sb.toString();
    }

    /**
     * description:  通过反射获取对象参数
     *
     * @param user
     * @param key
     * @return
     */
    public String getValues(UctUser user, String key) {
        Map<String, String> map = new HashMap<String, String>();
        String rtnValue = "";
        String rtnKey = "";
        try {
            Class<? extends UctUser> userCla = user.getClass();
            Field[] fs = userCla.getDeclaredFields();
            for (int i = 0; i < fs.length; i++) {
                Field f = fs[i];
                // 设置些属性是可以访问的
                f.setAccessible(true);
                // 得到此属性的值
                Object val = f.get(user);
                rtnKey = f.getName();
                if (StrUtil.isEmpty(val)) {
                    rtnValue = "";
                } else {
                    rtnValue = val.toString();
                }
                map.put(rtnKey, rtnValue);
            }
            rtnValue = map.get(key);
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return rtnValue;
    }

    /**
     * description:  获取当前对象中所有的key value值
     *
     * @param user
     * @return
     */
    public Map<String, String> getValues(UctUser user) {
        Map<String, String> map = new HashMap<String, String>();
        String rtnValue = "";
        String rtnKey = "";
        try {
            Class<? extends UctUser> userCla = user.getClass();
            Field[] fs = userCla.getDeclaredFields();
            for (int i = 0; i < fs.length; i++) {
                Field f = fs[i];
                // 设置些属性是可以访问的
                f.setAccessible(true);
                // 得到此属性的值
                Object val = f.get(user);
                rtnKey = f.getName();
                if (StrUtil.isEmpty(val)) {
                    rtnValue = "";
                } else {
                    rtnValue = val.toString();
                }
                map.put(rtnKey, rtnValue);
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return map;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserEname() {
        return userEname;
    }

    public void setUserEname(String userEname) {
        this.userEname = userEname;
    }

    public String getUserCname() {
        return userCname;
    }

    public void setUserCname(String userCname) {
        this.userCname = userCname;
    }

    public String getUserPass() {
        return userPass;
    }

    public void setUserPass(String userPass) {
        this.userPass = userPass;
    }

    public Integer getUserStatus() {
        return userStatus;
    }

    public void setUserStatus(Integer userStatus) {
        this.userStatus = userStatus;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getRegIp() {
        return regIp;
    }

    public void setRegIp(String regIp) {
        this.regIp = regIp;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public String getDelStatus() {
        return delStatus;
    }

    public void setDelStatus(String delStatus) {
        this.delStatus = delStatus;
    }

    public String getUserType() {
        return this.userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public String getCustomerType() {
        return this.customerType;
    }

    public void setCustomerType(String customerType) {
        this.customerType = customerType;
    }

    public Integer getUserLevel() {
        return this.userLevel;
    }

    public void setUserLevel(Integer userLevel) {
        this.userLevel = userLevel;
    }

    public String getOrgEname() {
        return orgEname;
    }

    public void setOrgEname(String orgEname) {
        this.orgEname = orgEname;
    }
}
